<?php
namespace iBrand\Shop\Core\Repositories;

use iBrand\Shop\Core\Models\BarCode;
use Prettus\Repository\Eloquent\BaseRepository;


class BarCodeRepository extends BaseRepository
{


    /**
     * Specify Model class name
     *
     * @return string
     */
    public function model()
    {
        return BarCode::class;
    }


    /**
     * 通过条形码code获取商品相关信息
     * @param $code
     * @return mixed
     */
    public function getGoodsByCode($code)
    {
        return $this->model->where('bar_code', $code)
            ->with('sku')
            ->with('sku.goods')
            ->whereHas('sku', function ($query) {
                return $query;
            })->first();
    }


}
